<template >
<el-row class=" loginform">
  <el-col :span="5" :push="10" >
  <el-form :model="loginForm" status-icon :rules="rules" ref="loginForm" label-width="100px" class="demo-ruleForm" >
    
    <el-form-item label="账号" prop="name">
      <el-input type="text" v-model="loginForm.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input v-model="loginForm.password"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('loginForm')">提交</el-button>
      <el-button @click="resetForm('loginForm')">重置</el-button>
    </el-form-item>
  </el-form>
  </el-col>
</el-row>
</template>


<script>
  export default {
    data() {
      return {
        loginForm: {
          name: '',
          password: '',
        },
        rules: {
          name: [{
            required: true,
            message: '请输入账号',
            trigger: 'blur'
          }],
          password: [{
              required: true,
              message: '请输入密码',
              trigger: 'blur'
            },
            {
              min: 8,
              max: 16,
              message: '长度在 8 到 16 个字符',
              trigger: 'blur'
            }
          ]
        },
        }
      },
      methods:{
        submitForm(formName) {
          alert(JSON.stringify(this.loginForm));
          /* axios.post('/login', JSON.stringify(this.loginForm),{
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
              }
          })
            .then(function(response) {
              this.$message({
                        showClose: true,
                        message: '恭喜你，登入成功！',
                        type: 'success'
                      });
            })
            .catch(function(error) {
              this.$message({
                        showClose: true,
                        message: '账号密码错误',
                        type: 'error'
                      });
            }); */
        },
        resetForm(formName) {
          this.$refs[loginForm].resetFields();
        }
      }
    }
</script>

<style>
  .loginform{
    margin-top: 250px;
  }
  button{
    margin: auto;
    padding: auto;
  }
</style>
